package com.tangyuan.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tangyuan.common.constant.CommonConstant;
import com.tangyuan.common.result.Result;
import com.tangyuan.common.util.iospay.AppleRequestProtocol;
import com.tangyuan.model.NyqmCustomerTixian;
import com.tangyuan.model.SysDictData;
import com.tangyuan.model.TyFinance;
import com.tangyuan.common.util.CommStatus;
import com.tangyuan.user.service.IUserBalanceService;
import com.tangyuan.user.service.SysDictDataService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: user_activity
 * @Author: jeecg-boot
 * @Date: 2024-03-20
 * @Version: V1.0
 */
@Api(tags = "user_activity")
@RestController
@RequestMapping("/user/userBalance")
@Slf4j
public class UserBalanceController {
    @Autowired
    private IUserBalanceService userBalanceService;
    @Autowired
    private SysDictDataService sysDictDataService;

    /**
     * 余额充值列表
     *
     * @return
     */
    @GetMapping("/rechargeList")
    public Result rechargeList() {
        LambdaQueryWrapper<SysDictData> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(SysDictData::getDictValue, SysDictData::getDictLabel, SysDictData::getRemark);
        wrapper.eq(SysDictData::getDictType, CommonConstant.DICT_TYPE_TY_RECHARGE);
        return Result.ok(sysDictDataService.list(wrapper));
    }


    /**
     * 余额充值
     *
     * @return
     */
    @PostMapping("/saveUserBalance")
    public Result<Object> saveUserBalance(@RequestHeader(name = "userId", required = false) Long userId, @RequestBody TyFinance tyFinance) {
        return userBalanceService.saveUserBalance(userId,tyFinance);
    }

    /**
     * 余额提现
     *
     * @return
     */
    @PostMapping("/cashUserBalance")
    public Result<Object> cashUserBalance(@RequestHeader(name = "userId", required = false) Long userId, @RequestBody NyqmCustomerTixian params) {
        return userBalanceService.cashUserBalance(userId,params);
    }

    /**
     * IOS充值票据校验
     *
     * @return
     */
    @PostMapping("/iosRechargeVerify")
    public Result<Object> iosRechargeVerify(@RequestBody AppleRequestProtocol request) {
        return userBalanceService.iosRechargeVerify(request);
    }
}
